package com.xu.system.controller;

import com.xu.minio.model.MinioFile;
import com.xu.system.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件服务控制器
 *
 * @Author: 许乾伟
 * @Date: 2024/12/20 9:34
 */
@RestController
@RequestMapping("file")
public class FileController {
    @Autowired
    IFileService fileService;
    /**
     * 导入文件
     * @param file
     * @return
     */
    @PostMapping(value = "upload")
    public MinioFile upload(@RequestPart("file") MultipartFile file) {
        return fileService.uploadMinioFile(file);
    }

    /**
     * 导入文件并保存关联数据
     * @param file 文件
     * @param sourceId 关联数据id
     * @param sourceCode 关联数据标识
     * @return
     */
    @PostMapping(value = "uploadAndSaveData")
    public MinioFile uploadAndSaveData(@RequestPart("file") MultipartFile file,Long sourceId, String sourceCode){
        return fileService.uploadAndSaveFileData(sourceId,sourceCode,file);
    }
}
